var ClubMergeTab = Item.extend({
    _ccsFileName: res.ClubMergeTab_json,
    _clubId: null,
    _clubList: [],

    initItem: function (clubId) {
        this._clubId = clubId;
        this.initTableView();
    },
    /**
     * 初始化TableView
     */
    initTableView: function () {
        var nodeContent = this._nodeList['nodeContent'];
        var tableViewSize = nodeContent.getContentSize();
        this._tableView = new cc.TableView(this, cc.size(tableViewSize.width, tableViewSize.height));
        this._tableView.setDelegate(this);
        this._tableView.setDirection(cc.SCROLLVIEW_DIRECTION_VERTICAL);
        this._tableView.setVerticalFillOrder(cc.TABLEVIEW_FILL_TOPDOWN);
        this._tableView.setPosition(nodeContent.getPosition());
        nodeContent.getParent().addChild(this._tableView);
    },


    _initClickListeners: function () {
        this._clickListeners = {
            'btn_find': '_clickFind',
            'btn_myClub': '_clickMyClub',
        }
    },
    _initEventListeners: function () {
        this._eventListeners = {};
        this._eventListeners[ClubMsgCode.FlushClubWithoutCache] = '_flushClubWithoutCacheCall';
        this._eventListeners[ClubMsgCode.ApplyComboClub] = '_applyComboClub';
    },

    refreshView: function () {

    },

    _clickFind: function () {
        var input = this._nodeList['input'].getString();
        var m_AllNum = /^[0-9]\d*$/.test(input);
        if (!m_AllNum || input.length == 0) {
            showAlert('输入亲友圈ID有误!');
            return;
        }
        if (this._clubId + '' == input) {
            showAlert('不能合入当前亲友圈!');
            return;
        }
        network.send(2103, {cmd: 'flushClubWithoutCache', dataset: 'min', club_id: parseInt(input)});
    },
    _clickMyClub: function () {
        this._clubList = [];

        // var clubs = getUidClubData(gameData.uid);
        var clubs = ClubDataManager.getAllClubData();
        if (clubs.length == 0) {
            showAlert('您没有其他亲友圈');
            return;
        }
        for (var i = 0; i < clubs.length; i++) {
            var club = clubs[i];
            if (club['_id'] != this._clubId) {
                this._clubList.push({clubId: club['_id'], name: club['name'], head: club['head']});
            }
        }
        this._tableView.reloadData();
    },

    _flushClubWithoutCacheCall: function (data) {
        if (data['result'] != 0) {
            return;
        }
        var clubInfo = data['info'];
        this._clubList = [];
        this._clubList.push({clubId: clubInfo['_id'], name: clubInfo['name'], head: clubInfo['head']});
        this._tableView.reloadData();
    },

    _applyComboClub: function (data) {
        if (data.result == 0) {
            showAlert('合并消息已发送，请联系要合入的亲友圈创建者，同意后方可完成合群!');
        }
    },


    tableCellAtIndex: function (table, idx) {
        var cell = table.dequeueCell();
        var node = null;
        if (cell == null) {
            cell = new cc.TableViewCell();
            node = addItem('ClubMergeItem', cell, this._clubList[idx], this._clubId);
            node.setName("itemCell");
        } else {
            node = cell.getChildByName("itemCell");
            node.setData(this._clubList[idx]);
        }
        return cell;
    },
    tableCellTouched: function (table, cell) {
    },
    tableCellSizeForIndex: function (table, idx) {
        return cc.size(970, 130);
    },
    numberOfCellsInTableView: function (table) {
        return this._clubList.length;
    },

});